home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.xa;
-
- import com.extensibility.rock.RBevelBorder;
- import java.awt.AWTEventMulticaster;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.BorderFactory;
- import javax.swing.Icon;
- import javax.swing.JComponent;
- import javax.swing.border.Border;
- import javax.swing.border.CompoundBorder;
- import javax.swing.border.EmptyBorder;
-
- public class QlickerBtn extends JComponent {
- static final int H_TEXTINSET = 0;
- static final int V_TEXTINSET = 1;
- static final int ICON_GAP = 3;
- Border normalBorder;
- Border depressedBorder;
- Border disabledBorder;
- String name;
- Icon icon;
- int nameWidth;
- boolean transparent;
- ActionListener actionListener;
- ML mouseListener;
- boolean cbState;
- boolean wasPopupTrigger;
-
- public QlickerBtn() {
- this("");
- this.transparent = true;
- }
-
- public QlickerBtn(String var1) {
- this.transparent = false;
- this.actionListener = null;
- this.mouseListener = new ML(this);
- this.cbState = false;
- this.name = var1;
- this.normalBorder = this.createNormalBorder();
- this.depressedBorder = this.createDepressedBorder();
- this.disabledBorder = this.createDisabledBorder();
- ((JComponent)this).setBorder(this.normalBorder);
- ((Component)this).addMouseListener(this.mouseListener);
- }
-
- public QlickerBtn(String var1, Icon var2) {
- this(var1);
- this.icon = var2;
- }
-
- public QlickerBtn(Icon var1) {
- this("");
- this.icon = var1;
- }
-
- protected Border createNormalBorder() {
- return new CompoundBorder(new RBevelBorder(0), new EmptyBorder(1, 2, 1, 2));
- }
-
- protected Border createDepressedBorder() {
- return new CompoundBorder(new RBevelBorder(1), new EmptyBorder(1, 2, 1, 2));
- }
-
- protected Border createDisabledBorder() {
- return BorderFactory.createEmptyBorder();
- }
-
- public Dimension getPreferredSize() {
- if (this.transparent) {
- return ((Component)this).getSize();
- } else {
- Insets var1 = this.normalBorder.getBorderInsets(this);
- return new Dimension(this.getNameWidth() + 0 + var1.left + var1.right, ((Component)this).getFontMetrics(((Component)this).getFont()).getAscent() + 2 + var1.bottom + var1.top);
- }
- }
-
- public void addActionListener(ActionListener var1) {
- this.actionListener = AWTEventMulticaster.add(this.actionListener, var1);
- }
-
- public void removeActionListener(ActionListener var1) {
- this.actionListener = AWTEventMulticaster.remove(this.actionListener, var1);
- }
-
- public void processEvent(ActionEvent var1) {
- if (this.actionListener != null) {
- this.actionListener.actionPerformed(var1);
- }
-
- }
-
- protected int getNameWidth() {
- if (this.nameWidth == 0) {
- this.nameWidth = ((Component)this).getFontMetrics(((Component)this).getFont()).stringWidth(this.name);
- if (this.icon != null) {
- this.nameWidth += this.icon.getIconWidth() + 3;
- }
- }
-
- return this.nameWidth;
- }
-
- protected int desiredWidth() {
- int var1 = this.getNameWidth() + 0 + 1;
- return var1;
- }
-
- protected void setIcon(Icon var1) {
- this.icon = var1;
- ((Component)this).repaint();
- }
-
- public void setPressed(boolean var1) {
- if (((Component)this).isEnabled()) {
- if (this.cbState != var1) {
- this.cbState = var1;
- Border var2 = this.normalBorder;
- this.normalBorder = this.depressedBorder;
- this.depressedBorder = var2;
- ((JComponent)this).setBorder(this.normalBorder);
- ((Component)this).repaint();
- }
- }
- }
-
- public void setEnabled(boolean var1) {
- if (var1 != ((Component)this).isEnabled()) {
- if (var1) {
- ((Component)this).addMouseListener(this.mouseListener);
- } else {
- ((Component)this).removeMouseListener(this.mouseListener);
- }
-
- ((JComponent)this).setBorder(var1 ? this.normalBorder : this.disabledBorder);
- super.setEnabled(var1);
- ((Component)this).repaint();
- }
- }
-
- public boolean isPressed() {
- return this.cbState;
- }
-
- public void paintComponent(Graphics var1) {
- super.paintComponent(var1);
- if (!this.transparent) {
- var1.setColor(((Component)this).getBackground());
- var1.fillRect(0, 0, ((JComponent)this).getWidth(), ((JComponent)this).getHeight());
- int var2 = var1.getFontMetrics().getAscent();
- var1.setColor(Color.black);
- Insets var3 = this.normalBorder.getBorderInsets(this);
- int var4 = var3.left + 0;
- int var5 = var3.top + 1 + var2;
- var1.drawString(this.name, var4, var5);
- if (this.icon != null) {
- this.icon.paintIcon(this, var1, ((JComponent)this).getWidth() - 0 - var3.right - this.icon.getIconWidth(), var5 - this.icon.getIconHeight());
- }
-
- }
- }
- }
-